package com.sangeng.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.sangeng.enums.AppHttpCodeEnum;

import java.io.Serializable;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;

    public ResponseResult() {
        this(AppHttpCodeEnum.SUCCESS.getCode(), AppHttpCodeEnum.SUCCESS.getMsg());
    }

    public ResponseResult(T data) {
        this(AppHttpCodeEnum.SUCCESS.getCode(), AppHttpCodeEnum.SUCCESS.getMsg(), data);
    }

    public ResponseResult(Integer code) {
        this(code, null);
    }

    public ResponseResult(Integer code, String msg) {
        this(code, msg, null);
    }

    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static <T> ResponseResult<T> errorResult(int code, String msg) {
        return new ResponseResult<T>(code, msg, null);
    }

    public static <T> ResponseResult<T> okResult() {
        return new ResponseResult<T>();
    }

    public static <T> ResponseResult<T> okResult(int code, String msg) {
        return new ResponseResult<T>(code, msg, null);
    }

    public static <T> ResponseResult<T> okResult(T data) {
        return new ResponseResult<T>(data);
    }

    public static <T> ResponseResult<T> errorResult(AppHttpCodeEnum enums) {
        return new ResponseResult<T>(enums.getCode(), enums.getMsg());
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}